
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hello-backbonejs</title>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
<script	src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js"></script>
<script	src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"></script>
<script>
	$(function() {
		var ListView = Backbone.View.extend({
			el: $('body'), // el attaches to existing element
		    events: {
		      'click button#add': 'addItem'
		    },
		    initialize: function(){
		      //_.bindAll(this, 'render', 'addItem'); // every function that uses 'this' as the current object should be in here
		      
		      this.counter = 0; // total number of items added thus far
		      this.render();
		    },

		    render: function(){
		      $(this.el).append("<button id='add'>Add list item</button>");
		      $(this.el).append("<ul></ul>");
		    },

		    addItem: function(){
		      this.counter++;
		      $('ul', this.el).append("<li>hello world"+this.counter+"</li>");
		    }
		  });

		  var listView = new ListView();  
	});
</script>
<body>
</body>
</html>
